package com.handpay.zztong.hp.klf;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.zztong.hp.R;

import java.text.ParseException;

/**
 * @author yanglun E-mail:sunshine_yangl@sina.com
 * @version 2015-12-28 上午11:13:51
 */
public class FourElementsScreen extends LinearLayout implements View.OnClickListener {

    private View.OnClickListener mClickListener;
    private LinearLayout layout;
    private Button hour_element_save_btn;

    public String four_element_bank_no;
    public String four_element_name;
    public String four_element_id_no;
    public String four_element_mobile_no;
    public TextView four_element_bank_no_tv;
    public TextView four_element_amount_tv;
    private EditText four_element_name_et;
    private EditText four_element_id_no_et;
    private EditText four_element_mobile_no_et;

    public FourElementsScreen(Context context, AttributeSet attrs) {
        super(context, attrs);
        layout = (LinearLayout) inflate(this.getContext(), R.layout.layout_four_element_screen, null);
        hour_element_save_btn = (Button) layout.findViewById(R.id.four_element_save_btn);
        four_element_bank_no_tv = (TextView) layout.findViewById(R.id.four_element_bank_no_tv);
        four_element_amount_tv = (TextView) layout.findViewById(R.id.four_element_amount_tv);
        four_element_name_et = (EditText) layout.findViewById(R.id.four_element_name_et);
        four_element_id_no_et = (EditText) layout.findViewById(R.id.four_element_id_no_et);
        four_element_mobile_no_et = (EditText) layout.findViewById(R.id.four_element_mobile_no_et);
        hour_element_save_btn.setOnClickListener(this);
        this.addView(layout);
    }

    public void setOnClickListener(View.OnClickListener clickListener) {
        mClickListener = clickListener;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.four_element_save_btn) {
            four_element_name = four_element_name_et.getText().toString().trim();
            four_element_id_no = four_element_id_no_et.getText().toString();
            four_element_mobile_no = four_element_mobile_no_et.getText().toString();

            // 持卡人姓名校验
            if (!CommonUtils.isRealName(four_element_name.trim())) {
                Toast.makeText(getContext(), R.string.four_element_name_tip, Toast.LENGTH_SHORT).show();
                return;
            }
            // 身份证号校验
            try {
                if (CommonUtils.IDCardValidate(four_element_id_no, true) != null) {
                    Toast.makeText(getContext(), R.string.four_element_id_no_tip, Toast.LENGTH_SHORT).show();
                    return;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            // 手机号校验
            if (!CommonUtils.isMobileNum(four_element_mobile_no)) {
                Toast.makeText(getContext(), R.string.four_element_mobile_no_tip, Toast.LENGTH_SHORT).show();
                return;
            }
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }

    }
}
